package com.note7_5;

import java.io.*;
import java.util.Arrays;

public class Question7_1 {

	public static void main(String[] args) throws IOException {
//		Scanner in = new Scanner(System.in);
//		System.out.println("输入文件位置：");
//		String path = in.nextLine();
		File f = new File("C:\\Users\\60973\\Desktop\\小图标\\android\\图片素材\\小图标\\0.png");
		FileInputStream is = new FileInputStream(f);
		String lastName = f.getName().substring(1+f.getName().lastIndexOf("."));
		System.out.println(lastName);
		int[] b = new  int[8];
		for(int i = 0; i < 8;i++){
			b[i] = is.read();
		}
		is.close();
		switch(lastName){
			case "bmp":
				if(b[0]==0x42 && b[1]==0x4D){
					System.out.println("是bmp合法文件！");
				}else{
					System.out.println("不是bmp合法文件！");
				}
			case "jpeg":
				if(b[0]==0xff && b[1]==0xd8){
					System.out.println("是jpeg合法文件！");
				}else{
					System.out.println("不是jpeg合法文件！");
				}
			case "png":
				int[] pnghead = {0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A};
				if(Arrays.equals(pnghead, b)){
					System.out.println("是png合法文件！");
				}else{
					System.out.println("不是png合法文件！");
				}
			case "git":
				int[] githead ={0x47,0x49,0x46,0x38,0x39,0x37,0x61};
				if(githead[0] == b[0] && githead[1] == b[1] && githead[2] == b[2] && githead[3] == b[3] && githead[4] == b[4] || githead[5] == b[4] && githead[6] == b[5]){
					System.out.println("是git合法文件！");
				}else{
					System.out.println("不是git合法文件！");
				}
		}
	}
}
